<template>
  <!-- 我们在测试模块进行了添加这行注释的操作，希望能够实现成功上传 -->
  <h1 style="text-align: center; color: red;">本页面为功能测试页面</h1>
  <nav>
    <ul class="menu">
      <li v-for="item in menuItems" :key="item.title" class="menu-item">
        <a href="#" @click="toggleSubmenu(item)">
          {{ item.title }}
        </a>
        <!-- 使用 v-if 来完全控制显示/隐藏，并配合过渡动画 -->
        <transition name="submenu-fade">
          <ul v-if="item.isSubmenuVisible" class="submenu">
            <li v-for="subitem in item.submenu" :key="subitem" class="submenu-item">
              <a href="#">{{ subitem }}</a>
            </li>
          </ul>
        </transition>
      </li>
      <li><a href="#">关于我们</a></li>
    </ul>
  </nav>



  <br>
  <hr>

  <el-dropdown>
    <span class="el-dropdown-link">
      Dropdown List
      <el-icon class="el-icon--right">
        <arrow-down />
      </el-icon>
    </span>
    <template #dropdown>
      <el-dropdown-menu style="background-color: #1943b0; border: none;">
        <el-dropdown-item>Action 1</el-dropdown-item>
        <el-dropdown-item>Action 2</el-dropdown-item>
        <el-dropdown-item>Action 3</el-dropdown-item>
        <el-dropdown-item disabled>Action 4</el-dropdown-item>
        <el-dropdown-item divided>Action 5</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>

  <br>
  <hr><br>
  <!-- 若依的数据 -->
   这里是从若依来的
  <div class="flex-box">
    <div v-for="item in categoryList" :key="item.id" class="transition-box">
        {{ item.name }}<br/>
        {{ item.updateTime }}
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import {listCategory} from '../../api/index'
const show = ref(true)
// 定义菜单项数据
const menuItems = ref([
  {
    title: '解决方案',
    submenu: [
      '电网&电站',
      '交通&水务',
      '油气&管道',
      '厂区&工地',
      '林业&环保',
      '安防&应急',
      '城市&港口',
    ],
    isSubmenuVisible: false, // 控制子菜单是否可见
  },
]);

//接收从后端来的数据
const categoryList = ref([])

// 切换子菜单的显示状态
const toggleSubmenu = (item) => {
  item.isSubmenuVisible = !item.isSubmenuVisible;
};


// 这里进行异步请求
onMounted(() => {
  listCategory().then(res => {
      console.log(res,"这是后端来的")
      categoryList.value = res.data.rows
  }
  ).catch(err => {
      console.log(err,"请求发生错误")
  })
})
</script>

<style scoped>

/* 后端数据展示测试 */
.flex-box{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  margin: 20px;
}




/* 下拉导航测试 */
.transition-box {
  margin-bottom: 10px;
  width: 200px;
  height: 100px;
  border-radius: 4px;
  background-color: #409eff;
  text-align: center;
  color: #fff;
  padding: 40px 20px;
  box-sizing: border-box;
  margin-right: 20px;
}


/* 基础样式 */
body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
}

nav {
  background-color: #333;
}

.menu {
  display: flex;
  list-style-type: none;
  padding: 0;
  margin: 0;
}

.menu-item {
  position: relative;
}

.menu-item>a {
  color: white;
  padding: 16px 20px;
  text-decoration: none;
  display: block;
}

.menu-item>a:hover {
  background-color: #575757;
}

/* 设置下拉菜单 */
.submenu {
  position: absolute;
  top: 100%;
  left: 0;
  background-color: #444;
  min-width: 200px;
  list-style-type: none;
  padding: 0;
  margin: 0;
  overflow: hidden;
  opacity: 0;
  /* 初始时设置为透明 */
  max-height: 0;
  /* 初始时设置为0，过渡时才会展开 */
  transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
  /* 平滑过渡 */
}

.submenu-item a {
  color: white;
  padding: 10px 15px;
  text-decoration: none;
  display: block;
}

.submenu-item a:hover {
  background-color: #575757;
}

/* 动画：子菜单显示时 */
.submenu-fade-enter-active {
  transition: opacity 0.3s ease-in-out, max-height 0.3s ease-in-out;
}

.submenu-fade-enter {
  opacity: 0;
  max-height: 0;
}

.submenu-fade-enter-to {
  opacity: 1;
  max-height: 500px;
  /* 展开时的最大高度，可以根据内容调整 */
}
</style>
